package com.toocms.jinjuhang.ui.mine.payment.bank

import android.app.Application
import androidx.databinding.ObservableArrayList
import com.blankj.utilcode.util.CollectionUtils
import com.toocms.jinjuhang.BR
import com.toocms.jinjuhang.R
import com.toocms.jinjuhang.config.Urls
import com.toocms.jinjuhang.config.UserRepository
import com.toocms.jinjuhang.data.center.BankCardListData
import com.toocms.jinjuhang.widget.view_model.requestData
import com.toocms.tab.base.BaseModel
import com.toocms.tab.base.BaseViewModel
import com.toocms.tab.binding.ItemBinding

/**
 * @Description:
 * @Author:         Zero
 * @CreateDate:     2023/5/18 14:02
 */
class BankListModel(application: Application) : BaseViewModel<BaseModel>(application) {

    val items = ObservableArrayList<BankListItemModel>()
    val itemBinding =
        ItemBinding.of<BankListItemModel>(BR.bankListItemModel, R.layout.item_bank_list)

    override fun onResume() {
        super.onResume()
        protocolList()
    }

    private fun protocolList() {
        val params = mutableMapOf<String, String?>()
        params["member_id"] = UserRepository.user.member_id
        requestData(
            Urls.Center.PROTOCOL_LIST,
            params,
            resultClass = BankCardListData::class.java,
            result = {
                items.clear()
                CollectionUtils.forAllDo(it.list) { _, item ->
                    items += BankListItemModel(this, item)
                }
            },
            error = {

            })
    }
}